//Jen Anderson
//CS 362
//Assignment 3
//unittest4.c

/*----------------------------------------------------------------------
  Unit test for discardCard()
  Code borrowed heavily from testUpdateCoins() example given on 
  	blackboard
  Tests whether discardCard()
	Test 1: detects a non-zero phase
	Test 2: detects 0 actions left	
	Test 3: returns -1 if the card is an action card
	Test 4: applies the card to the correct hand
	Test 5: reduces the number of actions
-----------------------------------------------------------------------*/

#include <assert.h>
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//set NOISY_TEST to 0 to remove print output
#define NOISY_TEST 1

void testDiscardCard()
{
	//Initialize the game
        int k[10] = {adventurer, council_room, feast, gardens, mine,remodel, smithy, village, baron, great_hall};
        struct gameState *game = newGame();
        initializeGame(3, k, 10, game);
        struct gameState *testGameState = malloc(sizeof(struct gameState));
        memcpy(testGameState, game, sizeof(struct gameState));
        
	/**************
	* Test 1
	**************/
	//Test whether the player's hand is decremented after this function is called
        discardCard(1, 0, testGameState, 0);
	assert(testGameState->handCount[0] = game->handCount[0] - 1);
	#if (NOISY_TEST == 1)
                printf("discardCard() successfully decremented the current player's hand.\n");
        #endif
          
	/*************
	* Test 2
	*************/
	//Discard a card for the control game
	//Trash a card from the test game
	//Make sure the control game and test game have the same number in their played card pile
	discardCard(1, 0, game, 0);
	discardCard(1, 0, testGameState, 1);
	assert(testGameState->playedCardCount = game->playedCardCount);
        #if (NOISY_TEST == 1)
                printf("discardCard() successfully didn't put a trashed card into the playedCard pile.\n");
        #endif
      
}

int main(int argc, char *argv[])
{
    testDiscardCard();
    return 0;
}
